package com.idlecode.config;

import cn.hutool.core.text.CharSequenceUtil;

/**
 * 数据库类型 枚举
 *
 */
public enum DbType {
	MySQL("com.mysql.cj.jdbc.Driver"), MariaDb("org.mariadb.jdbc.Driver"), Oracle("oracle.jdbc.driver.OracleDriver"),
	PostgreSQL("org.postgresql.Driver"), SQLServer("com.microsoft.sqlserver.jdbc.SQLServerDriver"),
	DM("dm.jdbc.driver.DmDriver"), Clickhouse("com.clickhouse.jdbc.ClickHouseDriver");

	private final String driverClass;

	DbType(String driverClass) {
		this.driverClass = driverClass;
	}

	public String getDriverClass() {
		return driverClass;
	}

	public static DbType getValue(String dbType) {
		if (CharSequenceUtil.equalsAny(dbType, "MySQL")) {
			return MySQL;
		}

		if (CharSequenceUtil.equalsAny(dbType, "MariaDB", "MariaDb")) {
			return MariaDb;
		}

		if (CharSequenceUtil.equalsAny(dbType, "Oracle")) {
			return Oracle;
		}

		if (CharSequenceUtil.equalsAny(dbType, "PostgreSQL")) {
			return PostgreSQL;
		}

		if (CharSequenceUtil.equalsAny(dbType, "SQLServer", "Microsoft SQL Server")) {
			return SQLServer;
		}

		if (CharSequenceUtil.equalsAny(dbType, "DM", "DM DBMS")) {
			return DM;
		}

		if (CharSequenceUtil.equalsAny(dbType, "Clickhouse")) {
			return Clickhouse;
		}

		return null;
	}
}